package com.jomoo.scs.utils;

public class ResultBean {

	private String code;
	private String message;
	private Object data;
	
	
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	
	public Object getData() {
		return data;
	}
	public void setData(Object data) {
		this.data = data;
	}
	public static ResultBean success(Object data){
		ResultBean result = new ResultBean();
		result.setCode("200");
		result.setData(data);
		result.setMessage("success");
		return result;
	}
	
	public static ResultBean fail(Exception e){
		ResultBean result = new ResultBean();
		result.setCode("500");
		StringBuffer sb = new StringBuffer(e.toString() + "\n"); 
		StackTraceElement[] messages = e.getStackTrace(); 
		int length = messages.length; 
		for (int i = 0; i < length; i++) { 
			sb.append("\t"+messages[i].toString()+"\n"); 
		} 
		result.setMessage(sb.toString());
		return result;
	}
	public static ResultBean fail(String msg){
		ResultBean result = new ResultBean();
		result.setCode("500");
		result.setMessage(msg);
		return result;
	}
}
